﻿<Window x:Class="FineSoft.ExtBuilder.Main"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	Title="MainWindow"

	xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
	xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"

	xmlns:FineViewModel="clr-namespace:FineSoft.ViewModels;assembly=FineSoft.ViewModels"
	xmlns:FineModel="clr-namespace:FineSoft.Models;assembly=FineSoft.Models"
	xmlns:FineControl="clr-namespace:FineSoft.Controls;assembly=FineSoft.Controls"
	xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
	DataContext="{Binding Main,Source={StaticResource Locator}}"
	WindowState="Maximized" Loaded="Window_Loaded" Name="Window">
	<Window.Resources>
		<Style x:Key="TreeViewItemStyle" TargetType="TreeViewItem">
			<Setter Property="Margin" Value="5 20 5 5" />
		</Style>
	</Window.Resources>
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition />
		</Grid.RowDefinitions>
		<Menu Grid.Row="0">
			<Menu.Items>
				<MenuItem Header="File">
					<MenuItem Header="Open a project..." Name="OpenMenu" Click="OpenMenu_Click" />
				</MenuItem>
			</Menu.Items>
		</Menu>
		<Grid Name="Grid" Grid.Row="1">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="150" />
				<ColumnDefinition />
				<ColumnDefinition Width="Auto" />
			</Grid.ColumnDefinitions>
			<TabControl Grid.Column="0" Margin="0,0,5,0">
				<TabItem Header="Files">
					<TreeView ItemsSource="{Binding TopDirectories}">
						<TreeView.ItemContainerStyle>
							<Style TargetType="TreeViewItem">
								<Setter Property="Margin" Value="0 2 0 2" />
							</Style>
						</TreeView.ItemContainerStyle>
						<TreeView.Resources>
							<HierarchicalDataTemplate DataType="{x:Type FineModel:Directory}" ItemsSource="{Binding Children}">
								<StackPanel Orientation="Horizontal">
									<Image Name="Icon" Source="Images/ToolBox/folder.png" />
									<TextBlock Text="{Binding Name}" />
								</StackPanel>
								<HierarchicalDataTemplate.Triggers>
									<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem}, Path=IsExpanded}" Value="True">
										<Setter TargetName="Icon" Property="Source" Value="Images/ToolBox/folder-open.png"/>
									</DataTrigger>
								</HierarchicalDataTemplate.Triggers>
							</HierarchicalDataTemplate>
							<DataTemplate DataType="{x:Type FineModel:File}">
								<ContentControl>
									<i:Interaction.Triggers>
				 						<i:EventTrigger EventName="MouseDoubleClick">
											<cmd:EventToCommand Command="{Binding ElementName=Window, Path=DataContext.TreeNodeDoubleClick}" CommandParameter="{Binding}" PassEventArgsToCommand="True" />
										</i:EventTrigger>
									</i:Interaction.Triggers>
									<StackPanel Orientation="Horizontal">
										<Image Source="Images/ToolBox/wheel.png" />
										<TextBlock Text="{Binding ShortName}" />
									</StackPanel>
								</ContentControl>
							</DataTemplate>
						</TreeView.Resources>
					</TreeView>
				</TabItem>
				<TabItem Header="ToolBox">
					<TreeView ItemsSource="{Binding ToolBoxItems}" dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="False">
						<TreeView.ItemContainerStyle>
							<Style TargetType="TreeViewItem">
								<Setter Property="Margin" Value="0 2 0 2" />
							</Style>
						</TreeView.ItemContainerStyle>
						<TreeView.Resources>
							<HierarchicalDataTemplate DataType="{x:Type FineModel:NameSpace}" ItemsSource="{Binding Children}">
								<StackPanel Orientation="Horizontal">
									<Image Name="Icon" Source="Images/ToolBox/folder.png" />
									<TextBlock Text="{Binding Name}" />
								</StackPanel>
								<HierarchicalDataTemplate.Triggers>
									<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem}, Path=IsExpanded}" Value="True">
										<Setter TargetName="Icon" Property="Source" Value="Images/ToolBox/folder-open.png"/>
									</DataTrigger>
								</HierarchicalDataTemplate.Triggers>
							</HierarchicalDataTemplate>
							<DataTemplate DataType="{x:Type FineModel:ComponentClass}">
								<ContentControl>
									<i:Interaction.Triggers>
										<i:EventTrigger EventName="MouseDoubleClick">
											<cmd:EventToCommand Command="{Binding ElementName=Window, Path=DataContext.ComponentNodeDoubleClick}" CommandParameter="{Binding}" PassEventArgsToCommand="True" />
										</i:EventTrigger>
									</i:Interaction.Triggers>
									<StackPanel Orientation="Horizontal">
										<Image Source="Images/ToolBox/wheel.png" />
										<TextBlock Text="{Binding ShortName}" />
									</StackPanel>
								</ContentControl>
							</DataTemplate>
						</TreeView.Resources>
					</TreeView>
				</TabItem>
			</TabControl>
			<GridSplitter Width="5" />
			<TabControl Grid.Column="1" Name="PageTabContainer" ItemsSource="{Binding Pages}">


				<TabControl.ItemTemplate>
					<DataTemplate>
						<DockPanel>
							<TextBlock Text="{Binding Document.File.Name}" DockPanel.Dock="Left" />
							<Button BorderBrush="Transparent" Background="Transparent">
								<Image DockPanel.Dock="Right" Source="Images/Editor/cross.png" SnapsToDevicePixels="True" Width="16" Height="16" />
							</Button>
						</DockPanel>
					</DataTemplate>
				</TabControl.ItemTemplate>
				<TabControl.ContentTemplate>
					<DataTemplate>
						<TextBox IsReadOnly="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
							<TextBox.Text>
								<Binding Path="Content" />
							</TextBox.Text>
						</TextBox>
					</DataTemplate>
				</TabControl.ContentTemplate>




				<TabItem>
					<TabItem.Header>
						<DockPanel>
							<TextBlock Text="Temp.htm" DockPanel.Dock="Left" />
							<Button BorderBrush="Transparent" Background="Transparent"><Image DockPanel.Dock="Right" Source="Images/Editor/cross.png" SnapsToDevicePixels="True" Width="16" Height="16" /></Button>
						</DockPanel>
					</TabItem.Header>
					<FineControl:Page Name="Page" ViewModel_SelectComponent="{Binding SelectComponentAtPoint}" ViewModel_AddComponent="{Binding AddComponentByType}">
						<FineControl:Page.Resources>
							<Style TargetType="{x:Type FineControl:Cover}">
								<Setter Property="dd:DragDrop.IsDragSource" Value="False" />
								<Setter Property="dd:DragDrop.IsDropTarget" Value="True" />
								<Setter Property="dd:DragDrop.DropHandler" Value="{Binding}" />
							</Style>
						</FineControl:Page.Resources>
					</FineControl:Page>
					<!--<Grid>
						<DockPanel>
							<Grid DockPanel.Dock="Top">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="Auto" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>
								<TextBlock Text="Page Title：" Grid.Column="0" Background="Transparent" VerticalAlignment="Center" />
								<TextBox Grid.Column="1" Text="{Binding Document.Title}" />
							</Grid>
							<Grid DockPanel.Dock="Top">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="Auto" />
									<ColumnDefinition />
								</Grid.ColumnDefinitions>
								<TextBlock Text="Add widgets to：" Grid.Column="0" Background="Transparent" VerticalAlignment="Center" />
								<ComboBox Name="ContainerList" Grid.Column="1" IsEnabled="{Binding ElementName=Window, Path=SelectedComponent.IsContainer}" ItemsSource="{Binding ElementName=Window, Path=SelectedComponent.Containers}" SelectedItem="{Binding ElementName=Window, Path=SelectedComponent.SelectedContainer}" HorizontalAlignment="Left">
									<ComboBox.ItemTemplate>
										<DataTemplate>
											<TextBlock Text="{Binding Key.Name}" />
										</DataTemplate>
									</ComboBox.ItemTemplate>
								</ComboBox>
							</Grid>
							<WebBrowser Name="WebBrowser" />
						</DockPanel>
						<FineControl:Cover Name="Cover" PlacementTarget="{Binding ElementName=WebBrowser}" dd:DragDrop.IsDragSource="False" dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding}" MouseLeftButtonDown="Cover_MouseLeftButtonDown" MouseRightButtonDown="Cover_MouseRightButtonDown" />
					</Grid>-->
				</TabItem>
			</TabControl>
			<!--Popup Name="Popup" IsOpen="True" AllowsTransparency="True" PlacementTarget="{Binding ElementName=WebBrowser}" Placement="Relative" Width="{Binding ElementName=WebBrowser,Path=ActualWidth}" Height="{Binding ElementName=WebBrowser,Path=ActualHeight}" dd:DragDrop.IsDragSource="False" dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding}">
				<StackPanel Background="White" Opacity="0.01" />
			</Popup-->
			<GridSplitter Grid.Column="2" Width="5" HorizontalAlignment="Left" />
			<TreeView Grid.Column="2" Background="Pink" HorizontalAlignment="Stretch" Margin="5,0,0,0">
				<TreeView.Items>
					<TreeViewItem Header="Ext2" />
				</TreeView.Items>
			</TreeView>
		</Grid>
	</Grid>
</Window>